import { validatenull } from "@/utils/validate";
import { calcDate } from "@/utils/date.js";
import { getStore } from "@/utils/store.js";
import { mapGetters } from "vuex";
// import admin from "@/utils/admin";

export default {
  data() {
    return {
      // 刷新token的时间
      refreshTime: "",
      // 刷新token锁
      refreshLock: false,
      refreshRadis: null
    }
  },
  computed: mapGetters(["isMenu", "isLock", "isCollapse", "website", "menu"]),
  methods: {
    // 定时检测token
    refreshToken() {
      this.refreshTime = setInterval(() => {
        const token =
          getStore({
            name: "token",
            debug: true,
          }) || {};
        const date = calcDate(token.datetime, new Date().getTime());
        if (validatenull(date)) return;
        if (date.seconds >= this.website.tokenTime && !this.refreshLock) {
          this.refreshLock = true;
          this.$store
            .dispatch("refreshToken")
            .then(() => {
              this.refreshLock = false;
            })
            .catch(() => {
              this.refreshLock = false;
            });
        }
      }, 10000);
    },
    // 初始化
    initWeb() {
      this.$store.dispatch("getDict").then(() => { });
    },
    // 打开菜单
    openMenu() {
    },
  },
  destroyed() {
    clearInterval(this.refreshRadis)
  }
}
